#封装接口，让test_shopping页面更整洁
from common.request_util import send
from common.file_util import *
def search_goods(name,goods_keyword,page=1,limit=8):
    data = {
        'path': '/api/products',
        'method': 'get',
        'params': {'keyword': goods_keyword, 'page': page, 'limit': limit}
    }
    return send(name,**data)

def add_group(name,group_name):
    data = {
        'path': '/adminapi/user/user_group/save.html',
        'method': 'post',
        'json': {'group_name': group_name},
        'headers': {
            'Authori-zation': f'Bearer {read_extract_variable("manage_token")}'}
    }
    return send(name, **data)

def add_coupon(name,testdata):
    data = {
        'path': '/adminapi/marketing/coupon/save_coupon',
        'method': 'post',
        'json': {"coupon_title": testdata['name'], "coupon_price": testdata['price'], "type": 0, "use_min_price": 0,
                 "coupon_time": 1, "start_use_time": 0, "end_use_time": 0, "start_time": 0, "end_time": 0,
                 "receive_type": 1, "is_permanent": testdata['permanent'], "total_count": testdata['permanent_count'],
                 "sort": 0, "status": testdata['status'], "product_id": "", "category_id": 0},
        'headers': {
            'Authori-zation': f'Bearer {read_extract_variable("manage_token")}'}

    }
    return send(name, **data)

def collect_goods(name,scid):
    data = {
        "path" :'/api/collect/add',
        "method":"post",
        "json":{"id": scid, "product": "product"},
        "headers":{"authori-zation":f'Bearer {read_extract_variable("token")}'}
    }
    return send(name,**data)

def add_cart(name,testdata):
    data = {
        'path' : '/api/cart/add',
        'method' : 'POST',
        'json' : {"productId":testdata['productId'],"cartNum":testdata['cartNum'],"new":0,"uniqueId":testdata['uniqueId'],"virtual_type":0},
        'headers' : {'Authori-zation': f'Bearer {read_extract_variable("token")}'}
    }
    return send(name,**data)

def confirm(name,cartId):
    data = {
        'path' : '/api/order/confirm',
        'method' : 'POST',
        'json' : {"cartId":f"{cartId}","new":0,"addressId":0},
        'headers' : {'Authori-zation': f'Bearer {read_extract_variable("token")}'}
    }
    return  send(name,**data)

def jiesuan(name,orderKey):
    data = {

    }
